package com.mrobuy.jdvc.dao.impl;

import com.gavel.database.SQLExecutor;
import com.mrobuy.jdvc.dao.VCItemExtPropDao;
import com.mrobuy.jdvc.dao.VCItemPropDao;
import com.mrobuy.jdvc.entity.VCItemExtPropValue;
import com.mrobuy.jdvc.entity.VCItemPropValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

@Repository("vcItemExtPropDao")
public class VCItemExtPropDaoImpl implements VCItemExtPropDao {

    private static Logger LOG = LoggerFactory.getLogger(VCItemPropDao.class);

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<VCItemExtPropValue> load(String productid) {
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT * from VC_ITEM_EXT_PROP_VALUE where PRODUCTID = ? ");
        try {
            List<VCItemExtPropValue> list = jdbcTemplate.query(sql.toString(), new Object[]{productid}, new BeanPropertyRowMapper(VCItemExtPropValue.class));
            return list;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }

        return Collections.EMPTY_LIST;
    }

    @Override
    public void insert(VCItemExtPropValue propValue) {

        try {
            SQLExecutor.tempLateInsert(propValue, jdbcTemplate);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void update(VCItemExtPropValue propValue) {
        try {
            SQLExecutor.tempLateUpate(propValue, jdbcTemplate);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
